#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A股股票查询分析器配置文件
包含所有可配置的参数和设置
"""

import os
from pathlib import Path

# 项目基础配置
PROJECT_NAME = "A股股票查询分析器"
VERSION = "1.0.0"
AUTHOR = "Stock Analyzer Team"

# 项目路径配置
BASE_DIR = Path(__file__).parent
DATA_DIR = BASE_DIR / "data"
LOGS_DIR = BASE_DIR / "logs"
CACHE_DIR = BASE_DIR / "cache"

# 确保目录存在
for directory in [DATA_DIR, LOGS_DIR, CACHE_DIR]:
    directory.mkdir(exist_ok=True)

# 数据源配置
DATA_SOURCE_CONFIG = {
    # 请求间隔时间（秒）
    "REQUEST_DELAY": 0.2,
    
    # 批量处理大小
    "BATCH_SIZE": 50,
    
    # 超时时间（秒）
    "TIMEOUT": 30,
    
    # 重试次数
    "MAX_RETRIES": 3,
    
    # 缓存过期时间（秒）
    "CACHE_EXPIRE_TIME": 300,  # 5分钟
}

# 股票筛选配置
FILTER_CONFIG = {
    # 趋势分析天数
    "TREND_ANALYSIS_DAYS": 20,
    
    # 历史数据获取天数
    "HISTORICAL_DAYS": 60,
    
    # 价格变化率阈值
    "PRICE_CHANGE_THRESHOLD": -0.05,  # -5%
    
    # 最小数据点数量
    "MIN_DATA_POINTS": 15,
    
    # 默认显示股票数量
    "DEFAULT_DISPLAY_COUNT": 50,
}

# 显示配置
DISPLAY_CONFIG = {
    # 显示的列
    "DISPLAY_COLUMNS": ['代码', '名称', '最新价', '涨跌幅', '市盈率-动态', '总市值'],
    
    # 价格显示精度
    "PRICE_PRECISION": 2,
    
    # 市值显示单位（亿元）
    "MARKET_VALUE_UNIT": 100000000,
    
    # 表格宽度
    "TABLE_WIDTH": 100,
}

# 日志配置
LOGGING_CONFIG = {
    "LOG_LEVEL": "INFO",
    "LOG_FORMAT": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    "LOG_FILE": LOGS_DIR / "stock_analyzer.log",
    "MAX_LOG_SIZE": 10 * 1024 * 1024,  # 10MB
    "BACKUP_COUNT": 5,
}

# 热门概念股配置
HOT_CONCEPTS = [
    "人工智能", "新能源汽车", "芯片概念", "5G概念",
    "医疗器械", "新能源", "军工概念", "区块链",
    "元宇宙", "储能", "光伏概念", "锂电池",
    "半导体", "云计算", "物联网", "大数据"
]

# 价格区间配置
PRICE_RANGES = [
    (0, 5, "超低价股 (0-5元)"),
    (5, 15, "低价股 (5-15元)"),
    (15, 30, "中低价股 (15-30元)"),
    (30, 60, "中价股 (30-60元)"),
    (60, 100, "中高价股 (60-100元)"),
    (100, 300, "高价股 (100-300元)"),
    (300, float('inf'), "超高价股 (300元以上)")
]

# 市值区间配置
MARKET_CAP_RANGES = [
    (0, 50, "小市值 (0-50亿)"),
    (50, 200, "中小市值 (50-200亿)"),
    (200, 500, "中等市值 (200-500亿)"),
    (500, 1000, "大市值 (500-1000亿)"),
    (1000, 5000, "超大市值 (1000-5000亿)"),
    (5000, float('inf'), "巨无霸市值 (5000亿以上)")
]

# 环境变量配置
def get_env_config():
    """获取环境变量配置"""
    return {
        "DEBUG": os.getenv("DEBUG", "False").lower() == "true",
        "LOG_LEVEL": os.getenv("LOG_LEVEL", "INFO"),
        "REQUEST_DELAY": float(os.getenv("REQUEST_DELAY", "0.2")),
        "CACHE_EXPIRE_TIME": int(os.getenv("CACHE_EXPIRE_TIME", "300")),
    }

# 合并环境变量配置
ENV_CONFIG = get_env_config()

# 更新配置
if ENV_CONFIG["DEBUG"]:
    LOGGING_CONFIG["LOG_LEVEL"] = "DEBUG"
    DATA_SOURCE_CONFIG["REQUEST_DELAY"] = 0.1

DATA_SOURCE_CONFIG["REQUEST_DELAY"] = ENV_CONFIG["REQUEST_DELAY"]
DATA_SOURCE_CONFIG["CACHE_EXPIRE_TIME"] = ENV_CONFIG["CACHE_EXPIRE_TIME"]
LOGGING_CONFIG["LOG_LEVEL"] = ENV_CONFIG["LOG_LEVEL"]

# API配置（如果需要特定API密钥）
API_CONFIG = {
    # 如果使用其他数据源，可以在这里配置API密钥
    # "API_KEY": os.getenv("STOCK_API_KEY", ""),
    # "API_SECRET": os.getenv("STOCK_API_SECRET", ""),
}

# 性能配置
PERFORMANCE_CONFIG = {
    # 并发请求数量
    "MAX_CONCURRENT_REQUESTS": 10,
    
    # 内存缓存大小
    "MEMORY_CACHE_SIZE": 1000,
    
    # 是否启用缓存
    "ENABLE_CACHE": True,
    
    # 是否启用多线程
    "ENABLE_MULTITHREADING": True,
} 